package cn.edu.scau.cmi.wujiaxian.exercise10;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Example10_6 {
	
	//FileWriter 和 FileReader可以直接读写字符
	public static void main(String[] args) {
		String content = "broadsword 哈哈哈哈";
		File file = new File("hello.txt");
		char[] a = content.toCharArray();
		FileWriter out;
		try {
			out = new FileWriter(file);
			out.write(a, 0, a.length);
			out.flush();
			out.close();
			FileReader in = new FileReader(file);
			StringBuilder stringBuilder = new StringBuilder();
			char[] tom = new char[10];
			int n = -1;
			while ((n = in.read(tom, 0, 10)) != -1) {
				String temp = new String(tom, 0, n);
				stringBuilder.append(temp);
			}
			in.close();
			System.out.println(stringBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
		
	}
	
}
